#include <QApplication>
#include <QThread>
#include <QTextCodec>
#include "tcommandexecprocess.h"
#include "tfrmupdatplugin.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //解析参数
    if(argc != 4) {
        exit(0);
    }
    QString devIP = argv[1];
    QString configFilePath = QTextCodec::codecForName("GB18030")->toUnicode(argv[2]);
    QString serverHandle = argv[3];

    //启动窗体
    TFrmUpDatPlugin frmUpDatPlugin;
    frmUpDatPlugin.setServerHandle(serverHandle.toInt());
    // frmUpDatPlugin.show();

    //启动升级线程
    TCommandExecProcess *commandExecProcess = new TCommandExecProcess;
    commandExecProcess->setConfig(configFilePath,devIP);
    QThread commandExecProcessThread;
    QObject::connect(&commandExecProcessThread,&QThread::finished,commandExecProcess,&TCommandExecProcess::deleteLater);
    QObject::connect(&commandExecProcessThread,&QThread::started,commandExecProcess,&TCommandExecProcess::slotStartUpDat);
    QObject::connect(commandExecProcess,&TCommandExecProcess::sigUpdatMessage,&frmUpDatPlugin,&TFrmUpDatPlugin::slotUpdatMessage);
    QObject::connect(commandExecProcess,&TCommandExecProcess::sigShowLog,&frmUpDatPlugin,&TFrmUpDatPlugin::slotShowLog);
    commandExecProcess->moveToThread(&commandExecProcessThread);
    commandExecProcessThread.start();

    int ret = a.exec();
    return ret;
}
